define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'trades/assets/withdrawsrelcard/index' + location.search,
                    // add_url: 'trades/assets/withdrawsrelcard/add',
                    // edit_url: 'trades/assets/withdrawsrelcard/edit',
                    // del_url: 'trades/assets/withdrawsrelcard/del',
                    // multi_url: 'trades/assets/withdrawsrelcard/multi',
                    // import_url: 'trades/assets/withdrawsrelcard/import',
                    table: 'activity_withdraws',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'amount', title: __('Amount'),operate:false},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'state', title: __('State'),
                            visible:false,
                            searchList: { "1":'已到账',"2":'处理中',"3":'已取消'}
                        },
                        {
                            field: 'state_text',
                            title: __('State'),
                            formatter:function(value,row) {
                                if (row['state'] == 1) {
                                    return '<span style="color:black">' + value + '</span>';
                                } else if (row['state'] == 2) {
                                    return '<span style="color:yellowgreen">' + value + '</span>';
                                } else if (row['state'] == 3) {
                                    return '<span style="color:red">' + value + '</span>';
                                }
                            }
                        },

                        {field: 'accountcard.bank_account', title: __('Accountcard.bank_account'), operate: false},
                        {field: 'accountcard.card_type', title: __('Accountcard.card_type'),operate:false},
                        {field: 'memo', title: __('Memo'), operate: false},
                        {field: 'operate_id', title: __('Operate_id'),operate:false},
                        {field: 'check_time', title: __('Check_time'), operate:false, addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            //
            $(document).on('click','.btn-spec_oper_btn', function () {
                var url = $(this).attr('data-url');
                var aid = $(this).attr('data-value');
                var msg = $(this).attr('data-title');
                if(!url) return false
                url = url +'?aid=' + aid;
                Fast.api.open(url,msg);
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        cash: function(){//提现验证
            $(document).on('click','.btn-cash', function () {
                var cash = $("#id-balance").val();//获取提现余额
                $('#c-amount').val(cash);//获取全部提现余额
              //  Fast.api.open(url,msg);
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});